var fs = require('fs');

var express = require('express');

var router = express.Router();

const {default: Axios} = require('axios');

function getHoneyedWords() {
  //https://pyq.shadiao.app/api.php 朋友圈
  //https://nmsl.shadiao.app/api.php?level=min&lang=zh_cn   骂人
  //https://chp.shadiao.app/api.php   情话
  //https://du.shadiao.app/api.php   毒鸡汤
  var url = 'https://chp.shadiao.app/api.php';
  //获取这个接口的信息
  return Axios.get(url);
}

router.get('/', function (request, response) {
  // response.send('hello');
  //会产生500错误代码
  // var reqData = req.body.data;
  // reqData = JSON.parse(reqData);
  // tenantData = JSON.parse(reqData);

  response.render('index.html', {
    name: 'lwf'
  });


  // console.log(request.query);

});

router.get('/students', function (request, response) {
  console.log(666);

  getHoneyedWords().then((res) => {
    response.status(200).json(res.data);
  });


});

router.get('/pinglun', function (request, response) {

  response.redirect('/');

});

router.get('/post', function (request, response) {

  response.redirect('/');

});

router.post('/post', function (request, response) {
  let {name} = request.body;
  console.log(8888, request.body);
  // console.log(name);

  // response.redirect('/');
  // response.send(name)

  response.render('index.html', {
    name
  });
});



module.exports = router;
